#include <iostream>
#include <Ice/Ice.h>
#include <BidirectionImpl.h>

int main()
{
#ifdef _WIN32
	system("chcp 65001");
#endif
	try {
		/*
		要将Ice.ACM.Client属性禁用掉。如果回调对象被关闭的话，只能重新
		if(server->ice_getConnection()->getAdapter() == NULL)
			 server->ice_getConnection()->setAdapter(adapter);
		server->addClient(ident);
		因为ICE有一个机制如果在一定的时间内，没有发生数据交互，连接会被关闭
		其实也可以利用一个hook线程对回调代理进行ice_ping()。
		*/
		::Ice::InitializationData iceInitData;
		iceInitData.properties = ::Ice::createProperties();
		iceInitData.properties->setProperty("Ice.ACM.Client", "0");
		iceInitData.properties->setProperty("Ice.ThreadPool.Server.Size", "4");
		iceInitData.properties->setProperty("Ice.ThreadPool.Server.SizeMax", "8");
		iceInitData.properties->setProperty("Ice.ThreadPool.Client.Size", "4");
		iceInitData.properties->setProperty("Ice.ThreadPool.Client.Size", "8");
		iceInitData.properties->setProperty("Ice.IPv6", "0");
		iceInitData.properties->setProperty("Ice.Default.Host", "0.0.0.0");
		iceInitData.properties->setProperty("Ice.Default.Timeout", "6000");
		iceInitData.properties->setProperty("Ice.Default.InvocationTimeout", "1000");
		::Ice::CommunicatorPtr ic = ::Ice::initialize(iceInitData);

		::Ice::ObjectAdapterPtr adapter = ic->createObjectAdapterWithEndpoints("simple", "default -p 10000");
		adapter->add(new Demo::CallbackSenderImpl(), ic->stringToIdentity("sender"));
		adapter->activate();
		ic->waitForShutdown();
	}
	catch (const ::Ice::Exception& ex) {
		std::cout << "异常:" << ex.what() << std::endl;
	}
	system("pause");
	return 0;
}